package com.taglab.chic.search;

/**
 * @author Markus Kobler
 */
public class Query {

  private String searchTerms;

  private int startPage = -1;

  private int count = -1;

  public Query(String searchTerms) {
    if( searchTerms == null ) throw new NullPointerException("Search terms cannot be null");
    this.searchTerms = searchTerms;
  }

  public Query(String searchTerms, int startPage, int count) {
    this( searchTerms );
    this.startPage = startPage;
    this.count = count;
  }

  public String getSearchTerms() {
    return searchTerms;
  }

  public int getStartPage() {
    return startPage;
  }

  public void setStartPage(int startPage) {
    this.startPage = startPage;
  }

  public int getCount() {
    return count;
  }

  public void setCount(int count) {
    this.count = count;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Query that = (Query) o;

    if (startPage != that.startPage) return false;
    if (count != that.count) return false;
    if (!searchTerms.equals(that.searchTerms)) return false;

    return true;
  }

  @Override
  public int hashCode() {
    int result = searchTerms.hashCode();
    result = 31 * result + startPage;
    result = 31 * result + count;
    return result;
  }

  @Override
  public String toString() {
    final StringBuilder sb = new StringBuilder();
    sb.append("Query");
    sb.append("{searchTerms='").append(searchTerms).append('\'');
    sb.append(", startPage=").append(startPage);
    sb.append(", count=").append(count);
    sb.append('}');
    return sb.toString();
  }
}
